<?php

class ConfigsController extends Controller
{
  public $layout='//layouts/admin';

  public function filters()
  {
    return array(
      'accessControl',
    );
  }

  public function accessRules()
  {
    return array(
      /*
      array('allow',  // allow all users to perform 'index' and 'view' actions
        'actions'=>array('index','view'),
        'users'=>array('*'),
      ),
      */
      array('allow', // allow authenticated user to perform 'create' and 'update' actions
        'actions'=>array('list','update'),
        'users'=>array('@'),
      ),
      array('deny',  // deny all users
        'users'=>array('*'),
      ),
    );
  }

  public function actionUpdate($id)
  {
    $model=$this->loadModel($id);

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Configs']))
    {
      $model->attributes=$_POST['Configs'];
      if($model->save())
        $this->redirect(array('list'));
    }

    $this->render('update',array(
      'model'=>$model,
    ));
  }

  public function actionList()
  {
    $dataProvider=new CActiveDataProvider('Configs');
    $this->render('list',array(
      'dataProvider'=>$dataProvider,
    ));
  }

  public function loadModel($id)
  {
    $model=Configs::model()->findByPk($id);
    if($model===null)
      throw new CHttpException(404,'The requested page does not exist.');
    return $model;
  }

  /**
   * Performs the AJAX validation.
   * @param CModel the model to be validated
   */
  protected function performAjaxValidation($model)
  {
    if(isset($_POST['ajax']) && $_POST['ajax']==='config-form')
    {
      echo CActiveForm::validate($model);
      Yii::app()->end();
    }
  }
}
